package com.baoer;

import com.alibaba.fastjson.JSONObject;

/**
 * @Author: YING
 * @CreateTime: 2025-04-07
 * @Description:
 * @Version: 1.0
 */


public class R extends JSONObject {
    private static final long serialVersionUID = 1L;

    public R(RCode code) {
        super.put("code", code.getCode());
        super.put("msg", code.getMsg());
    }

    public R(RCode code, Object data) {
        super.put("code", code.getCode());
        super.put("msg", code.getMsg());
        super.put("dataset", data);
    }

    public static R ok() {
        return new R(RCode.SUCCESS);
    }

    public static R er() {
        return new R(RCode.FAIL);
    }

    public static R ok(Object data) {
        return new R(RCode.SUCCESS, data);
    }
    public static R er(Object data) {return new R(RCode.FAIL, data);}

    public static R unauth() {
        return new R(RCode.UNAUTHENCATIED);
    }
    // 添加 getCode 方法
    public int getCode() {
        return this.getIntValue("code");
    }
    // 获取数据
    public Object getData() {
        return this.get("dataset"); // 使用正确的键 "dataset" 来获取数据
    }


}
